<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>全选按钮</title>
</head>
<body>
    <table border>
        <tr>
            <td>
                <input onclick='allChecked()' type="checkbox"/>
            </td>
            <td>姓 名</td>
            <td>爱 好</td>
        </tr>
        <tr>
             <td>
                <input border type="checkbox"/>
            </td>
            <td>张 三</td>
            <td>抽 烟</td>
        </tr>
        <tr>
             <td>
                <input type="checkbox"/>
            </td>
            <td>李 四</td>
            <td>喝 酒</td>
        </tr>
        <tr>
             <td>
                <input border type="checkbox"/>
            </td>
            <td>王老五</td>
            <td>烫 头</td>
        </tr>
        <tr>
             <td>
                <input border type="checkbox"/>
            </td>
            <td>王麻子</td>
            <td>打麻将</td>
        </tr>
    </table>
    <script>
    var chk=document.getElementsByTagName('input')
    function allChecked(){

        for(var i=1;i<chk.length;i++) {
            if(chk[i].checked == false){
                for(var i = 0;i<chk.length;i++){
                    chk[i].checked = true;
                }
            }
        }

            if(chk[0].checked){
                for(var i = 1;i<chk.length;i++){
                    chk[i].checked=true;
                }
            } else {
                for(var i = 1;i<chk.length;i++){
                    chk[i].checked=false;
                }
            }
}
    </script>

</body>
</html>